package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"jk-webook/internal/repository/dao"
)

func InitDb() *gorm.DB {
	db, err := gorm.Open(mysql.Open(""))
	if err != nil {
		panic(err)
	}
	err = dao.InitTable(db)
	if err != nil {
		panic(err)
	}
	return db
}

type DoSomething interface {
	DoABC() string
}
type DoSomethingFunc func() string

func (d DoSomethingFunc) DoABC() string {
	return d()
}
func WrapReq[T any](fn func(ctx *gin.Context, req T) (any, error)) gin.HandlerFunc {
	return func(ctx *gin.Context) {
		var req T
		if err := ctx.Bind(&req); err != nil {
			return
		}
		_, err := fn(ctx, req)
		if err != nil {
			fmt.Println(err)
		}
		ctx.JSON(200, gin.H{})
	}
}
func PrintSlice[T any](s []T) {
	for _, v := range s {
		fmt.Println(v)
	}
}
